<template>
  <div class="forbidden">
    <div class="forbidden-content">
      <h1>403</h1>
      <h2>权限不足</h2>
      <p>抱歉，您没有权限访问该页面或执行该操作。</p>
      <el-button type="primary" @click="goBack">返回</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ForbiddenPage',
  methods: {
    goBack() {
      // 检查用户是否登录
      const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
      
      if (isLoggedIn) {
        // 尝试从localStorage获取菜单
        const menuString = localStorage.getItem('permissionMenus');
        if (menuString) {
          try {
            const menus = JSON.parse(menuString);
            if (menus && menus.length > 0) {
              // 有菜单权限，跳转到第一个菜单
              this.$router.push(menus[0].path);
            } else {
              // 没有菜单，跳转登录页
              this.$router.push('/login');
            }
          } catch (e) {
            this.$router.push('/login');
          }
        } else {
          this.$router.push('/login');
        }
      } else {
        this.$router.push('/login');
      }
    }
  }
}
</script>

<style scoped>
.forbidden {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.forbidden-content {
  text-align: center;
  padding: 30px;
  border-radius: 8px;
  background-color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

h1 {
  font-size: 72px;
  margin: 0;
  color: #F56C6C;
}

h2 {
  margin: 20px 0;
  color: #606266;
}

p {
  margin-bottom: 30px;
  color: #909399;
}
</style> 